#include "StdAfx.h"
#include "Player.h"


Player::Player(Ogre::SceneManager* manager)
{
	this->mSceneMgr = manager;

	// Position camera
	mVitesse = 80;
    mVitesseRotation = 0.2;
}


Player::~Player(void)
{	
	delete this->mSceneMgr;
}

void Player::Update(OIS::Mouse *mMouse, OIS::Keyboard *mKeyboard, Ogre::Camera *mCamera, const Ogre::FrameEvent& evt, Map *map)
{
	// Position du joueur
	Ogre::Vector3 deplacement = Ogre::Vector3::ZERO;
	mMouvement = mVitesse * evt.timeSinceLastFrame;

	if (mKeyboard->isKeyDown(OIS::KC_A))
	{
		deplacement.x -= mMouvement;
	}
	if (mKeyboard->isKeyDown(OIS::KC_D))
	{
		deplacement.x += mMouvement;
	}
	if (mKeyboard->isKeyDown(OIS::KC_W))
	{
		deplacement.z -= mMouvement;
	}
	if (mKeyboard->isKeyDown(OIS::KC_S))
	{
		deplacement.z += mMouvement;
	}

	mCamera->moveRelative(deplacement);

	Ogre::Vector3 newPos = mCamera->getPosition();
	if (newPos.x > 450) 
	{
		newPos.x = 450;
	}
	
	if (newPos.x < -450)
	{
		newPos.x = -450;
	}
	
	if (newPos.z > 450)
	{
		newPos.z = 450;
	}
	
	if (newPos.z < -450)
	{
		newPos.z = -450;
	}

	mCamera->setPosition(newPos);

	// Orientation du joueur
	const OIS::MouseState &mouseState = mMouse->getMouseState();
	mRotationY = Ogre::Degree(-mouseState.X.rel * mVitesseRotation);
	mCamera->yaw(mRotationY);
}
